{% extends "base.html" %}

{% block title %}WTForms - Flask Forms Demo{% endblock %}

{% block content %}
<h2>WTForms Integration</h2>

<div class="row">
    <div class="col-md-6">
        <form method="POST">
            {{ form.hidden_tag() }}
            
            <div class="form-field">
                {{ form.username.label(class="form-label") }}
                {{ form.username(class="form-control") }}
                {% if form.username.errors %}
                    <div class="text-danger">
                        {% for error in form.username.errors %}
                            <small>{{ error }}</small>
                        {% endfor %}
                    </div>
                {% endif %}
                <div class="form-text">Choose a unique username (3-20 characters)</div>
            </div>
            
            <div class="form-field">
                {{ form.email.label(class="form-label") }}
                {{ form.email(class="form-control") }}
                {% if form.email.errors %}
                    <div class="text-danger">
                        {% for error in form.email.errors %}
                            <small>{{ error }}</small>
                        {% endfor %}
                    </div>
                {% endif %}
                <div class="form-text">Enter a valid email address</div>
            </div>
            
            <div class="form-field">
                {{ form.password.label(class="form-label") }}
                {{ form.password(class="form-control") }}
                {% if form.password.errors %}
                    <div class="text-danger">
                        {% for error in form.password.errors %}
                            <small>{{ error }}</small>
                        {% endfor %}
                    </div>
                {% endif %}
                <div class="form-text">Password must be at least 8 characters</div>
            </div>
            
            <div class="form-field">
                {{ form.confirm_password.label(class="form-label") }}
                {{ form.confirm_password(class="form-control") }}
                {% if form.confirm_password.errors %}
                    <div class="text-danger">
                        {% for error in form.confirm_password.errors %}
                            <small>{{ error }}</small>
                        {% endfor %}
                    </div>
                {% endif %}
            </div>
            
            <div class="form-field">
                {{ form.age.label(class="form-label") }}
                {{ form.age(class="form-control") }}
                {% if form.age.errors %}
                    <div class="text-danger">
                        {% for error in form.age.errors %}
                            <small>{{ error }}</small>
                        {% endfor %}
                    </div>
                {% endif %}
                <div class="form-text">Enter your age (13-120)</div>
            </div>
            
            <div class="form-field">
                {{ form.country.label(class="form-label") }}
                {{ form.country(class="form-select") }}
                {% if form.country.errors %}
                    <div class="text-danger">
                        {% for error in form.country.errors %}
                            <small>{{ error }}</small>
                        {% endfor %}
                    </div>
                {% endif %}
            </div>
            
            <div class="form-field">
                {{ form.biography.label(class="form-label") }}
                {{ form.biography(class="form-control", rows="3") }}
                {% if form.biography.errors %}
                    <div class="text-danger">
                        {% for error in form.biography.errors %}
                            <small>{{ error }}</small>
                        {% endfor %}
                    </div>
                {% endif %}
                <div class="form-text">Tell us about yourself (optional)</div>
            </div>
            
            <div class="form-field">
                <div class="form-check">
                    {{ form.agree_terms(class="form-check-input") }}
                    {{ form.agree_terms.label(class="form-check-label") }}
                </div>
                {% if form.agree_terms.errors %}
                    <div class="text-danger">
                        {% for error in form.agree_terms.errors %}
                            <small>{{ error }}</small>
                        {% endfor %}
                    </div>
                {% endif %}
            </div>
            
            <div class="form-field">
                {{ form.subscribe_newsletter.label(class="form-label") }}
                {{ form.subscribe_newsletter(class="form-check-input") }}
            </div>
            
            {{ form.submit(class="btn btn-primary") }}
            <a href="{{ url_for('index') }}" class="btn btn-secondary">Back</a>
        </form>
    </div>
    
    <div class="col-md-6">
        <div class="card">
            <div class="card-header">
                <h5>Form Data</h5>
            </div>
            <div class="card-body">
                {% if form_data %}
                    <h6>Submitted Data:</h6>
                    <pre>{{ form_data|pprint }}</pre>
                {% else %}
                    <p>Submit the form to see the data here.</p>
                {% endif %}
            </div>
        </div>
        
        <div class="card mt-3">
            <div class="card-header">
                <h5>About WTForms</h5>
            </div>
            <div class="card-body">
                <p>WTForms provides robust form handling with:</p>
                <ul>
                    <li>Automatic form rendering</li>
                    <li>Built-in validators</li>
                    <li>CSRF protection</li>
                    <li>Custom validation rules</li>
                    <li>Easy integration with Flask-WTF</li>
                </ul>
                <p>Benefits over manual form handling:</p>
                <ul>
                    <li>Less boilerplate code</li>
                    <li>Better security</li>
                    <li>Easier maintenance</li>
                    <li>Consistent validation</li>
                </ul>
            </div>
        </div>
    </div>
</div>
{% endblock %}